/**
 * 
 */
/**

 * @ClassName:     package-info.java
 * @Description:   TODO 
 * @author          zhangjb
 * @version         V1.0  
 * @Date           2016年11月30日 下午2:43:54 

 */
package com.daisuxia.web.controller;

import java.util.Date;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.daisuxia.back.utils.ServiceResult;
import com.daisuxia.web.pojo.JsAwardRecord;
import com.daisuxia.web.pojo.JsDrawrollsRecord;
import com.daisuxia.web.pojo.JsLoanPerson;
import com.daisuxia.web.pojo.JsStepRecord;
import com.daisuxia.web.service.JsAwardRecordService;
import com.daisuxia.web.service.JsDrawrollsRecordService;
import com.daisuxia.web.service.JsLoanPersonService;
import com.daisuxia.web.service.JsStepRecordService;
import com.daisuxia.web.util.PageConfig;

/**
 * 统计中奖用户
 * @author Administrator
 *
 */


@Controller
 
@RequestMapping("/xianjin/sysXianjinCard")
 public class SysXianJinCardController extends BaseController {
	

	@Autowired
	private JsAwardRecordService jsAwardRecordService;
	@Autowired
	private JsDrawrollsRecordService jsDrawrollsRecordService;
	@Autowired
	private JsStepRecordService jsStepRecordService;
	@Autowired
	private AwardCenterController awardCenterController;
	@Autowired
	private JsLoanPersonService jsLoanPersonService;
	
	/**
	 * 中奖用户统计
	 * @param jsAwardRecord
	 * @param request
	 * @param response
	 * @param model
	 * @return
	 */
	@RequestMapping(value = {"list", ""})
	public String list(JsAwardRecord jsAwardRecord, HttpServletRequest request, HttpServletResponse response, Model model) {

		
		PageConfig<JsAwardRecord>  page= null;
				//jsAwardRecordService.findPage(new Page<JsAwardRecord>(request, response) , jsAwardRecord);
		model.addAttribute("page", page);
		return "modules/xianjinCard/jsAwardRecordList";
	}
	
	/**
	 * 抽奖号码统计
	 * @param jsAwardRecord
	 * @param request
	 * @param response
	 * @param model
	 * @return
	 */
	@RequestMapping(value = {"drawrollslist", ""})
	public String drawrollslist(JsDrawrollsRecord jsDrawrollsRecord, HttpServletRequest request, HttpServletResponse response, Model model) {


		jsDrawrollsRecord.setPeriods(Integer.parseInt(request.getParameter("periods").toString()));
		jsDrawrollsRecord.setIsValid(1);
		PageConfig<JsDrawrollsRecord>  page= null;
				//jsDrawrollsRecordService.findPage(new Page<JsDrawrollsRecord>(request, response) , jsDrawrollsRecord);
		model.addAttribute("page", page);
		model.addAttribute("periods", Integer.parseInt(request.getParameter("periods").toString()));
		return "modules/xianjinCard/jsDrawrollsRecordList";
	}
	
	/**
	 * 行为记录统计
	 * @param jsAwardRecord
	 * @param request
	 * @param response
	 * @param model
	 * @return
	 */
	@RequestMapping(value = {"jsStepRecordlist", ""})
									
	public String jsStepRecordlist(JsStepRecord jsStepRecord, HttpServletRequest request, HttpServletResponse response, Model model) {

		
		PageConfig<JsStepRecord>  page= null;
				//jsStepRecordService.findPage(new Page<JsStepRecord>(request, response) , jsStepRecord);
		model.addAttribute("page", page);
//		model.addAttribute("jsStepRecord", jsStepRecord);
		return "modules/xianjinCard/jsStepRecordList";
	}
	
	/**
	 * 中奖用户修改
	 * @param jsAwardRecord
	 * @param request
	 * @param response
	 * @param model
	 * @return
	 */
	@RequestMapping(value = {"jsAwardRecordEditor", ""})
									
	public String jsAwardRecordEditor(JsAwardRecord jsAwardRecord, Model model) {

		if (StringUtils.isNotBlank(jsAwardRecord.getId())){
			//jsAwardRecord = jsAwardRecordService.get(jsAwardRecord);
		}
		model.addAttribute("jsAwardRecord", jsAwardRecord);
		return "modules/xianjinCard/jsAwardRecordEditor";
	}
	/**
	 * 中奖用户修改提交
	 * @param jsAwardRecord
	 * @param request
	 * @param response
	 * @param model
	 * @return
	 */
	@RequestMapping(value = {"jsAwardRecordSave", ""})
									
	public String jsAwardRecordSave(JsAwardRecord jsAwardRecord, HttpServletRequest request,  Model model) {

//		if (!beanValidator(model, jsAwardRecord)){
//			return jsAwardRecordEditor(jsAwardRecord, model);
//		}
		if(jsAwardRecord.getStatus()==2){
			jsAwardRecord.setAwardTime(new Date());
		}
		jsAwardRecordService.save(jsAwardRecord);
		//addMessage(redirectAttributes, "保存抽奖信息成功");
		return "/xianjin/sysXianjinCard/list";
	}
	
	/**
	 * 中奖
	 * @param jsAwardRecord
	 * @param request
	 * @param response
	 * @param model
	 * @return
	 */
	@RequestMapping(value = {"drawAward", ""})
									
	public String drawAward(JsAwardRecord jsAwardRecord, HttpServletRequest request, HttpServletResponse response, Model model) {

		String periods = request.getParameter("periods");
		String id = request.getParameter("id");
		ServiceResult serviceResult = new ServiceResult("500", "系统异常！");
		if (StringUtils.isNotBlank(periods)&&StringUtils.isNotBlank(id)){
			JsAwardRecord jsAwardRecords = new JsAwardRecord();
			  serviceResult =	awardCenterController.runDrawBlack(request, response, model);
		}
		return "/xianjin/sysXianjinCard/list";
	}
	
	

	/**
	 * 用户记录统计
	 * @param jsAwardRecord
	 * @param request
	 * @param response
	 * @param model
	 * @return
	 */
	@RequestMapping(value = {"jsLoanPersonList", ""})
									
	public String jsLoanPersonList(HttpServletRequest request, HttpServletResponse response, Model model) {

		
		PageConfig<JsLoanPerson>  page= null;
				//jsLoanPersonService.findUserPage(new Page<JsLoanPerson>(request, response) , jsLoanPerson);
		model.addAttribute("page", page);
		return "modules/xianjinCard/jsLoanPersonList";
	}
//	
//	
//	/**
//	 * 后台添加用户行为
//	 * @param jsAwardRecord
//	 * @param request
//	 * @param response
//	 * @param model
//	 * @return
//	 */
// 	@RequestMapping(value = {"jsLoanPersonAdd", ""})
//									
//	public String jsLoanPersonAdd(JsAwardRecord jsAwardRecord, HttpServletRequest request, HttpServletResponse response, Model model,RedirectAttributes redirectAttributes) {
//
//		
//		ServiceResult serviceResult = new ServiceResult("500", "系统异常！");
//		
//			SysHelpCenter jsAwardRecords = new SysHelpCenter();
//			serviceResult = awardCenterController.addUserStepBlack(jsAwardRecords, request, response, model);
//		
//		addMessage(redirectAttributes, serviceResult.getMsg());
//		return "redirect:"+Global.getAdminPath()+"/xianjin/sysXianjinCard/jsLoanPersonList";
//	}
//	
 	/**
	 * 用户信息修改
	 * @param jsAwardRecord
	 * @param request
	 * @param response
	 * @param model
	 * @return
	 */
 	@RequestMapping(value = {"jsLoanPersonEditor", ""})									
	public String jsLoanPersonEditor(JsLoanPerson jsLoanPerson,Model model ) {

		
 		if (StringUtils.isNotBlank(jsLoanPerson.getId())){
 			jsLoanPerson = null;
 					//jsLoanPersonService.get(jsLoanPerson);
		}
		model.addAttribute("jsLoanPerson", jsLoanPerson);
		return "modules/xianjinCard/jsLoanPersonEditor";
	}
 	
 	/**
	 * 用户信息修改
	 * @param jsAwardRecord
	 * @param request
	 * @param response
	 * @param model
	 * @return
	 */
 	@RequestMapping(value = {"jsLoanPersonSave", ""})									
	public String jsLoanPersonSave(JsLoanPerson jsLoanPerson, HttpServletRequest request, HttpServletResponse response, Model model) {

// 		if (!beanValidator(model, jsLoanPerson)){
//			return jsLoanPersonEditor(jsLoanPerson, model);
//		}		
 		jsLoanPerson.setUpdatedAt(new Date());		
 		jsLoanPersonService.save(jsLoanPerson);
//		addMessage(redirectAttributes, "保存用户信息成功");
		return "/xianjin/sysXianjinCard/jsLoanPersonList";
	}
}